package com.disdr;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class 下载司机证件 {
    static Map<Integer,String> map = new HashMap<Integer,String>();

    public static void main(String[] args) throws IOException {
        toMap();
        FileReader fileReader = new FileReader("E://司机车辆.txt");
        BufferedReader br = new BufferedReader(fileReader);
        String line = br.readLine();
        for(;line!=null;line = br.readLine()) {
            String[] str = line.split("\t");
            String parenPath = "E://司机数据//"+str[0];
            File parenFile = new File(parenPath);
            parenFile.mkdirs();
            for(int i =1;i<str.length;i++) {
                yy(parenPath, str, i);
            }
        }
    }

    private static void yy(String parenPath,String[] str,int index) throws IOException {
        String name = map.get(index);
        if(name == null){
            return;
        }
        String url = str[index];
        if(url==null || url.equals("")){
            return;
        }
        if(index >8){
            String vnum = str[8];
            name = name+"_"+vnum;
        }
        name = name + url.substring(url.lastIndexOf("."));
        File file1 = new File(parenPath+"/"+name);
        byte[] bytes = HttpRequest.get(url).execute().bodyBytes();
        BufferedOutputStream bufferedOutputStream =FileUtil.getOutputStream(file1);
        bufferedOutputStream.write(bytes);

    }

    private static void toMap(){
        map.put(1, "身份证正面");
        map.put(2, "身份证反面");
        map.put(3, "驾驶证");
        map.put(4, "从业资格证");
        map.put(5, "驾驶证副页");
        map.put(6,  "道路运输经营许可证");
        map.put(12,"行驶证");
        map.put(13, "道理运输许可证");
    }

}
